package servlet;

import dao.InfoDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		InfoDao dao = new InfoDao();
		String username = request.getParameter("name");
		String password = request.getParameter("pass");
		
		boolean ok = dao.login(username, password);
		
		if(ok) {
			request.getRequestDispatcher("info").forward(request, response);
		}else {
			request.getRequestDispatcher("login.jsp?isOk=no").forward(request, response);
		}
	
			
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}



}